import 'package:flutter/material.dart';
import '../utils/general.dart';


class FFRow extends StatelessWidget {

  final String title;
  final String subtitle;
  final bool   bold;
  final Widget leading;
  final Widget trailing;
  final EdgeInsets padding;
  final VoidCallback onpress;
  final TextStyle textStyle;

  static const temp = EdgeInsets.all(16.0);
  FFRow({
    this.title,
    this.subtitle,
    this.bold = false,
    this.leading,
    this.trailing, 
    this.padding = temp,
    this.onpress,
    this.textStyle,
  });


  List<Widget> acquireNeedTitleSubtitle(BuildContext context) {
    double scale = widthScale(context);
    List<Widget> list = [];
    if (title != null) {
      list.add(
        Text(
          title, 
          style:textStyle != null ? textStyle : TextStyle(
            fontSize:16 * scale, 
            color:Color.fromRGBO(56, 56, 56, 1.0), 
            fontWeight: bold ? FontWeight.bold : FontWeight.normal
          ), 
          textAlign: TextAlign.left,
        )
      );
    } 
    if (subtitle != null) {
      list.add(  
        Text(
          subtitle, 
          style:textStyle != null ? textStyle : TextStyle(
            fontSize:11 * scale, 
            color:Color.fromRGBO(128, 128, 128, 1.0), 
          ), 
          textAlign: TextAlign.left,
        )
      );
    }
    return list;
  }

  Widget acquireNeedPart(BuildContext context) {
    if (leading == null) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: acquireNeedTitleSubtitle(context),
      );
    }else {
      return Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children:[
          Padding(
            padding: EdgeInsets.only(right:10.0),
            child: leading,
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: acquireNeedTitleSubtitle(context),
          ),
        ]
      );
    }

  }

  /// cell
  Widget listCell(BuildContext context,) {
    return GestureDetector(
      onTap:onpress,
      child: Container(
        color:Colors.white,
        child: Column(
          children:<Widget>[
            Padding(
              padding: padding,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  acquireNeedPart(context),
                  trailing,
                ],
              ),
            ),

            Container(
              color: separatorLineColor,
              padding: EdgeInsets.fromLTRB(16.0, 0, 16.0, 0),
              height: 1,
            )
          ],
        ),
      ),
    );
  }
  


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return listCell(context);
  }

}